package com.shunda.ysdgj.manager.controller;

import com.shunda.ysdgj.manager.service.CaptchaService;
import com.shunda.ysdgj.manager.service.system.SysUserService;
import com.shunda.ysdgj.model.dto.system.LoginDto;
import com.shunda.ysdgj.model.vo.ResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "管理员接口")
@RestController
@RequestMapping("/api/v1/admin/system/index")
@RequiredArgsConstructor
public class IndexController {

    private final SysUserService sysUserService;
    private final CaptchaService captchaService;

    @Operation(summary = "管理员登录")
    @PostMapping("login")
    public ResultVo login(@RequestBody LoginDto loginDto) {
        return ResultVo.success(sysUserService.login(loginDto));
    }

    @Operation(summary = "生成验证码")
    @GetMapping("captcha")
    public ResultVo captcha() {
        return ResultVo.success(captchaService.generate());
    }

    @Operation(summary = "获取当前登录管理员信息")
    @GetMapping("getUserInfo")
    public ResultVo getUserInfo(HttpServletRequest request) {
        String token = request.getHeader("token");
        return ResultVo.success(sysUserService.getUserInfo(token));
    }

    @Operation(summary = "获取当前登录管理员菜单")
    @GetMapping("getUserMenus")
    public ResultVo getUserMenus(HttpServletRequest request) {
        String token = request.getHeader("token");
        return ResultVo.success(sysUserService.getUserMenus(token));
    }

    @Operation(summary = "管理员退出登录")
    @GetMapping("logout")
    public ResultVo logout(HttpServletRequest request) {
        String token = request.getHeader("token");
        sysUserService.logout(token);
        return ResultVo.success();
    }

}
